package com.qf.utils;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

/*
杨威
2021/9/7
21:04
*/
public class DruidUtil {
    private  static DruidDataSource ds;
    static {
        try {
            InputStream resourceAsStream = DruidUtil.class.getResourceAsStream("/db.properties");
            Properties properties=new Properties();
            properties.load(resourceAsStream);
            ds = (DruidDataSource)DruidDataSourceFactory.createDataSource(properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static Connection getConnection(){
        Connection connection=null;
        try {
            connection=ds.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return connection;
    }
}
